﻿using Management.Systeam.Domaina;
using Management.Systeam.ErrorCode;
using Management.Systeam.Read.Apis.Application.Command.Resourceses;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Management.Systeam.Read.Apis.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ResourcesAllController : ControllerBase
    {
        IMediator mediator;

        public ResourcesAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpPost]
        public async Task<ApiResult<int>> AddResources(AddResourcesesCommand AddResourcesesCommand)
        {
            try
            {
                return await mediator.Send(AddResourcesesCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取资源列表一次
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPeaging<ApiResult<List<Resources>>>> ShowResources([FromQuery] ShowResourcesCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        public async Task<ApiResult<int>> DelResources([FromBody] DelResourcesesCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        public async Task<ApiResult<int>> UpdateResources(UpdateResourcesCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
